package cn.llk.mall.controller.router;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.servlet.http.HttpServletRequest;

/**
 * index router
 */
@Controller
public class IndexRouterController {

    @GetMapping("/goShoppingCart")
    public String goShoppingCart() {
        return "shoppingCart";
    }

    @GetMapping("/goSuccess")
    public String goSuccess() {
        return "success";
    }

    @GetMapping("/goUser")
    public String user() {
        return "user";
    }

    @GetMapping("/goGoods/{goodsId}")
    public String view(@PathVariable String goodsId, Model model) {
        model.addAttribute("id", goodsId);
        return "view";
    }

    @GetMapping("/goLogin")
    public String goLogin() {
        return "login";
    }

    @GetMapping("/goRegister")
    public String goRegister() {
        return "register";
    }

    @GetMapping("/logout")
    public String logout(Model model, HttpServletRequest request) {
        // 删除保存的user信息
        model.addAttribute("user", null);
        request.getSession().removeAttribute("user");
        return "index";
    }

}
